<template>
  <div class="newsinfo-container">
    <h3>{{newsinfo.title}}</h3>
    <div class="detail">
      <span>发表时间: {{newsinfo.add_time | dataFormat}}</span>
      <span>点击: {{newsinfo.click}}次</span>
    </div>
  <hr>
  <div class="content" v-html="newsinfo.content"></div>
  <!-- 评论子组件 -->
  <comment :id="id"></comment>
  </div>
</template>

<script>
import {Toast} from 'mint-ui'
import comment from '../subcomponents/comment.vue'

export default {
  data(){
    return{
      id: this.$route.params.id, //将url地址中传递过来的id值挂载到data上，方便以后调用
      newsinfo:{}
    }
  },
  created(){
    this.getNewsInfo()
  },
  methods:{
    getNewsInfo(){
      this.$http.get('api/getnew/' + this.id)
      .then(result => {
        if(result.body.status === 0){
          this.newsinfo = result.body.message[0]
          //console.log(this.newsinfo)
        }else{
          Toast('获取新闻数据失败')
        }
      })
    }
  },
  components:{
    comment
  } 
}
</script>

<style lang="scss" scoped>
.newsinfo-container{
  padding: 2px 4px;
  h3{
  margin: 10px 0;
  font-size: 16px;
  text-align: center;
  color: red;
  }
  .detail{
    margin: 0 10px;
    font-size:12px;
    color: #226aff;
    display: flex;
    justify-content: space-between;
  }
  .content{
    img {
      width:100%;
    }
  }
}
</style>


